<?php

namespace app\common\model\knowbase;

use app\admin\model\Admin;
use think\Model;


class Progress extends Model
{


   
    protected $name = 'knowbase_progress';

   
    protected $autoWriteTimestamp = 'integer';

   
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

   
    protected $append = [
        'type_text'
    ];


    public function getTypeList()
    {
        return ['project_look' => __('Type project_look'), 'project_add' => __('Type project_add'), 'project_soft_delete' => __('Type project_soft_delete'), 'project_restore' => __('Type project_restore'), 'project_hard_delete' => __('Type project_hard_delete'), 'project_update' => __('Type project_update'), 'project_weight' => __('Type project_weight'), 'project_pdf' => __('Type project_pdf'), 'project_html' => __('Type project_html'), 'project_clone' => __('Type project_clone'), 'page_look' => __('Type page_look'), 'page_add' => __('Type page_add'), 'page_restore' => __('Type page_restore'), 'page_soft_delete' => __('Type page_soft_delete'), 'page_hard_delete' => __('Type page_hard_delete'), 'page_update' => __('Type page_update'), 'page_weight' => __('Type page_weight'), 'page_clone' => __('Type page_clone'), 'page_history_delete' => __('Type page_history_delete'), 'progress_history_delete' => __('Type progress_history_delete'), 'template_add' => __('Type template_add'), 'template_delete' => __('Type template_delete'), 'template_update' => __('Type template_update'), 'sitemap' => __('Type sitemap')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list  = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 添加日志
     * @param        $type        类型
     * @param        $related_id  关联ID
     * @param string $remark      额外记录 可空
     */
    public static function addLog($type, $related_id, $remark = '')
    {
        $msg = [
            'project_look'            => __('progress_project_look'),
            'project_add'             => __('progress_project_add'),
            'project_soft_delete'     => __('progress_project_soft_delete'),
            'project_restore'         => __('progress_project_restore'),
            'project_hard_delete'     => __('progress_project_hard_delete'),
            'project_update'          => __('progress_project_update'),
            'project_weight'          => __('progress_project_weight'),
            'project_pdf'             => __('progress_project_pdf'),
            'project_html'            => __('progress_project_html'),
            'project_clone'           => __('progress_project_clone'),
            'page_look'               => __('progress_page_look'),
            'page_add'                => __('progress_page_add'),
            'page_restore'            => __('progress_page_restore'),
            'page_soft_delete'        => __('progress_page_soft_delete'),
            'page_hard_delete'        => __('progress_page_hard_delete'),
            'page_update'             => __('progress_page_update'),
            'page_weight'             => __('progress_page_weight'),
            'page_clone'              => __('progress_page_clone'),
            'page_history_delete'     => __('progress_page_history_delete'),
            'progress_history_delete' => __('progress_progress_history_delete'),
            'template_add'            => __('progress_template_add'),
            'template_delete'         => __('progress_template_delete'),
            'template_update'         => __('progress_template_update'),
            'sitemap'                 => __('progress_sitemap'),
        ];
        self::create([
            'admin_id'   => \app\admin\library\Auth::instance()->id,
            'type'       => $type,
            'related_id' => $related_id,
            'msg'        => $msg[$type] ?? 'unkown',
            'remark'     => $remark,
        ]);
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class, 'admin_id', '', [], 'LEFT')->setEagerlyType(0);
    }
}
